namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmKeEditor : FormListEditor
    {
        private IContainer components;
        private LabelControl lblMa_Ke;
        private LabelControl lblTen_Ke;
        private LabelControl lblTen_Ke_E;
        private TextControl txtMa_Ke;
        private TextControl txtTen_Ke;
        private TextControl txtTen_Ke_E;

        public FormDmKeEditor()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDmKeEditor));
            this.txtMa_Ke = new TextControl();
            this.lblMa_Ke = new LabelControl();
            this.txtTen_Ke = new TextControl();
            this.lblTen_Ke = new LabelControl();
            this.txtTen_Ke_E = new TextControl();
            this.lblTen_Ke_E = new LabelControl();
            base.SuspendLayout();
            base.txtMa_Loai3.FirstFilter = "Type = 'KE3'";
            base.txtMa_Loai3.Location = new Point(0x18c, 0x5e);
            base.txtMa_Loai3.Size = new Size(0x85, 20);
            base.txtMa_Loai3.TabIndex = 5;
            base.txtMa_Loai2.FirstFilter = "Type = 'KE2'";
            base.txtMa_Loai2.Location = new Point(0x103, 0x5e);
            base.txtMa_Loai2.Size = new Size(0x86, 20);
            base.txtMa_Loai2.TabIndex = 4;
            base.txtMa_Loai1.FirstFilter = "Type = 'KE1'";
            base.txtMa_Loai1.Location = new Point(0x7b, 0x5e);
            base.txtMa_Loai1.Size = new Size(0x85, 20);
            base.txtMa_Loai1.TabIndex = 3;
            base.lblPhan_Loai.Location = new Point(12, 0x61);
            this.txtMa_Ke.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Ke.CheckTextSearched = false;
            this.txtMa_Ke.DisabledForeColor = Color.Empty;
            this.txtMa_Ke.Font = new Font("Arial", 8.25f);
            this.txtMa_Ke.Location = new Point(0x7b, 0x1c);
            this.txtMa_Ke.MaxLength = 0x20;
            this.txtMa_Ke.Name = "txtMa_Ke";
            this.txtMa_Ke.OldValue = null;
            this.txtMa_Ke.Size = new Size(0x85, 20);
            this.txtMa_Ke.TabIndex = 0;
            this.txtMa_Ke.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Ke.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Ke.Value = null;//manager.GetObject("txtMa_Ke.Value");
            this.lblMa_Ke.AutoSize = true;
            this.lblMa_Ke.Font = new Font("Arial", 8.25f);
            this.lblMa_Ke.Location = new Point(12, 0x1f);
            this.lblMa_Ke.Name = "lblMa_Ke";
            this.lblMa_Ke.Size = new Size(0x3e, 14);
            this.lblMa_Ke.TabIndex = 4;
            this.lblMa_Ke.Text = "Mã kệ hàng";
            this.txtTen_Ke.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Ke.CheckTextSearched = false;
            this.txtTen_Ke.DisabledForeColor = Color.Empty;
            this.txtTen_Ke.Font = new Font("Arial", 8.25f);
            this.txtTen_Ke.Location = new Point(0x7b, 50);
            this.txtTen_Ke.MaxLength = 128;
            this.txtTen_Ke.Name = "txtTen_Ke";
            this.txtTen_Ke.OldValue = null;
            this.txtTen_Ke.Size = new Size(0x196, 20);
            this.txtTen_Ke.TabIndex = 1;
            this.txtTen_Ke.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Ke.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Ke.Value = null;//manager.GetObject("txtTen_Ke.Value");
            this.lblTen_Ke.AutoSize = true;
            this.lblTen_Ke.Font = new Font("Arial", 8.25f);
            this.lblTen_Ke.Location = new Point(12, 0x35);
            this.lblTen_Ke.Name = "lblTen_Ke";
            this.lblTen_Ke.Size = new Size(0x38, 14);
            this.lblTen_Ke.TabIndex = 4;
            this.lblTen_Ke.Text = "M\x00f4 tả vị tr\x00ed";
            this.txtTen_Ke_E.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Ke_E.CheckTextSearched = false;
            this.txtTen_Ke_E.DisabledForeColor = Color.Empty;
            this.txtTen_Ke_E.Font = new Font("Arial", 8.25f);
            this.txtTen_Ke_E.Location = new Point(0x7b, 0x48);
            this.txtTen_Ke_E.MaxLength = 128;
            this.txtTen_Ke_E.Name = "txtTen_Ke_E";
            this.txtTen_Ke_E.OldValue = null;
            this.txtTen_Ke_E.Size = new Size(0x196, 20);
            this.txtTen_Ke_E.TabIndex = 2;
            this.txtTen_Ke_E.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Ke_E.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Ke_E.Value = null;//manager.GetObject("txtTen_Ke_E.Value");
            this.lblTen_Ke_E.AutoSize = true;
            this.lblTen_Ke_E.Font = new Font("Arial", 8.25f);
            this.lblTen_Ke_E.Location = new Point(12, 0x4b);
            this.lblTen_Ke_E.Name = "lblTen_Ke_E";
            this.lblTen_Ke_E.Size = new Size(0x52, 14);
            this.lblTen_Ke_E.TabIndex = 4;
            this.lblTen_Ke_E.Text = "M\x00f4 tả tiếng Anh";
            base.AddTitleText = "Thêm mới kệ hàng";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x222, 128);
            base.Controls.Add(this.lblTen_Ke_E);
            base.Controls.Add(this.lblTen_Ke);
            base.Controls.Add(this.lblMa_Ke);
            base.Controls.Add(this.txtTen_Ke_E);
            base.Controls.Add(this.txtTen_Ke);
            base.Controls.Add(this.txtMa_Ke);
            base.EditTitleText = "Sửa kệ hàng";
            base.FirstFreeCode = "KE1";
            base.Name = "FormDmKeEditor";
            base.SecondFreeCode = "KE2";
            this.Text = "Thêm mới kệ hàng";
            base.ThirdFreeCode = "KE3";
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            base.Controls.SetChildIndex(this.txtMa_Ke, 0);
            base.Controls.SetChildIndex(this.txtTen_Ke, 0);
            base.Controls.SetChildIndex(this.txtTen_Ke_E, 0);
            base.Controls.SetChildIndex(this.lblMa_Ke, 0);
            base.Controls.SetChildIndex(this.lblTen_Ke, 0);
            base.Controls.SetChildIndex(this.lblTen_Ke_E, 0);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (string.IsNullOrEmpty(this.txtMa_Ke.Text))
            {
                MessageBox.Show("Chưa nhập mã kệ hàng!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Ke.Text))
            {
                MessageBox.Show("Chưa nhập m\x00f4 tả vị tr\x00ed!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Ke"] = this.txtMa_Ke.Value;
            localCurrentRow["Ten_Ke"] = this.txtTen_Ke.Value;
            localCurrentRow["Ten_Ke_E"] = this.txtTen_Ke_E.Value;
            localCurrentRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            DmKeDataAccess access = new DmKeDataAccess();
            if (base.ShowMessage(localCurrentRow, access.SaveRow(base.NewChecked, localCurrentRow)))
            {
                return false;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Ke.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Ke.Value = base.LocalCurrentRow["Ma_Ke"];
            this.txtTen_Ke.Value = base.LocalCurrentRow["Ten_Ke"];
            this.txtTen_Ke_E.Value = base.LocalCurrentRow["Ten_Ke_E"];
            base.txtMa_Loai1.Value = base.LocalCurrentRow["Ma_Loai1"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.OnShow();
        }
    }
}

